package cn.lau.core.db.dao;

import cn.lau.core.db.dao.entity.User;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import java.io.Serializable;


@Repository
public class CoreDBTest  extends HibernateDaoSupport{

    @Autowired
    private SessionFactory sessionFactory;

    //获取Session
    protected Session getSession() {
        return this.getHibernateTemplate().getSessionFactory().getCurrentSession();
    }

    public void print(){
        System.out.println("core-db");
    }

    public void database(){

//        Type load = getHibernateTemplate().load(Type.class, "1");
//        System.out.println(JSONUtils.objectToJson(load));

        Session session = getSession();
        HibernateTemplate hibernateTemplate = getHibernateTemplate();
        User user = new User();
        user.setName("hehel");
        user.setNumber("123123123");
        Serializable save = hibernateTemplate.save(user);
        System.out.println(1);
    }
}
